module.exports = function (grunt) {
    'use strict';
    require('load-grunt-tasks')(grunt);
    // 配置任务  
    grunt.initConfig({
        clean: {
            last: [
                '.tmp',
                'dist/*.js',
                'dist/*.css',
                'dist/*.css.map'
            ],
            clstmp: ['.tmp']
        },
        copy: {
            dist: {
                files: [
                    {
                        expand: true,
                        cwd: './',
                        src: ['image/**', 'grapheditor.css', 'font/*', 'jscolor/*', 'theme/*','resources/*','lib/*'],
                        dest: 'dist'
                    },
                    {
                        expand: true,
                        cwd: './src/',
                        src: ['css/*','images/*','resources/*','index.js'],
                        dest: 'dist'
                    }
                ]
            }
        },
        concat: {
            // options: {
            // banner: '(function () {\n',
            // footer: '})();'
            // },
            dist: {
                src: [
                    'src/EditorUi.js',
                    'src/Editor.js',
                    'src/Sidebar.js',
                    'src/Graph.js',
                    'src/Format.js',
                    'src/Shapes.js',
                    'src/Actions.js',
                    'src/Menus.js',
                    'src/Toolbar.js',
                    'src/Dialogs.js',
                ], // 指向你的JavaScript源文件  
                dest: 'dist/js/drawio.js', // 合并后的文件输出路径  
            },
        },
        babel: {
            options: {
                sourceMap: false,
                presets: ['@babel/preset-env']
            },
            dist: {
                files: {
                    'dist/js/drawio.js': 'dist/js/drawio.js',
                },
            }
        },
        uglify: {
            my_target: {
                files: {
                    'dist/js/drawio.min.js': ['dist/js/drawio.js'], // 将合并后的文件压缩并输出  
                }
            }
        },
    });

    // 加载插件  
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');

    // 注册任务  
    grunt.registerTask('build', ['clean:last', 'copy', 'concat', 'babel', 'uglify']);
};